﻿using Application.Dto;
using Application.IAppSrevices;
using AutoMapper;
using Domain.Entitys;
using Domain.Repositorys;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.AppSrevices
{
    public class CMService : ICMService
    {
        private readonly IMapper mapper;
        private readonly ICMRepositoy cMRepositoy;
        private readonly ICMKRepositoy cMKRepositoy;

        public CMService(IMapper mapper,ICMRepositoy cMRepositoy, ICMKRepositoy cMKRepositoy)
        {
            this.mapper = mapper;
            this.cMRepositoy = cMRepositoy;
            this.cMKRepositoy = cMKRepositoy;
        }

        /// <summary>
        /// 级联查询
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public List<Cascader> Cascaders()
        {
            return cMRepositoy.Cascaders();
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="cMAddDto"></param>
        /// <returns></returns>
        public async Task<int> CMAddAsync(CMAddDto cMAddDto)
        {
            CM cm = mapper.Map<CM>(cMAddDto);
            return await cMRepositoy.CMAddAsync(cm);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<int> CMDeleteAsync(int id)
        {
            return await cMRepositoy.CMDeleteAsync(id);
        }
        
        public async Task<int> CMDeleteAsync1(string id)
        {
            return await cMRepositoy.CMDeleteAsync1(id);
        }
        
        /// <summary>
        /// 查询全部职位数据
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<List<CM>> CMFillAsync()
        {
            return cMRepositoy.CMFillAsync();
        }

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public async Task<List<CM>> CMKSelect(int pageIndex, int pageSize)
        {
            return await cMRepositoy.CMSelect(pageIndex, pageSize);
        }
        /// <summary>
        /// 查询总条数
        /// </summary>
        /// <returns></returns>
        public int CMSelectCount()
        {
            return cMRepositoy.CMSelectCount();
        }

        public Task<List<CM>> CMSelectId(string id)
        {
            return cMRepositoy.CMSelectId(id);
        }

        public Task<CM> CMSelectName(string name)
        {
            return cMRepositoy.CMSelectName(name);
        }

        //查询下拉框数据
        public async Task<List<CMK>> CMSelectOpiton()
        {
            return await cMRepositoy.CMSelectOpiton();
        }
    }
}
